import React, { Component } from 'react';
import { messages } from "share/common";
import {Form, Input, Switch, Alert, InputNumber} from 'antd';
import Priority from 'components/template/priority/priority';

const FormItem = Form.Item;

class AutoAuditRuleSlideHead extends Component {

  static  propTypes = {
    onChange: React.PropTypes.func,
    disabled: React.PropTypes.bool
  };

  handlePriority = (priority) => {
    this.props.onChange(priority);
  };

  render() {
    const { getFieldDecorator, getFieldValue } = this.props.form;
    const { head: { id }, disabled, priority } = this.props;
    const formItemLayout = {
      labelCol: {
        xs: { span: 24 },
        sm: { span: 6 },
      },
      wrapperCol: {
        xs: { span: 24 },
        sm: { span: 14 },
      },
    };
    return (
      <div>
        <FormItem label={messages('common.column.status')/*状态*/} {...formItemLayout}>
          {getFieldDecorator('enabled', {
            valuePropName: 'checked',
            initialValue: true
          })(
            <Switch disabled={disabled}/>
          )}
          &nbsp;&nbsp;{getFieldValue('enabled') ? messages('common.status.enable')/*启用*/ : messages('common.status.disable')/*禁用*/}
        </FormItem>
        <Priority
          top={'SET_OF_BOOK'}
          single={false}
          onChange={this.handlePriority}
          disabled={disabled}
          showCompany={false}
          disabledTop={!!id}
          defaultValue={priority}
          formItemLayout={formItemLayout}
        />
        <FormItem
          label={messages('expense-14.key422')/*优先级*/}
          {...formItemLayout}
        >
          {getFieldDecorator('priority', {
            rules: [{
              required: true,
              message: messages('common.please.input')/*请输入*/,
            }]
          })(
            <InputNumber disabled={!!id || disabled} min={1}/>
          )}
        </FormItem>
        <FormItem
          label={messages('expense-14.key420')/*规则编码*/}
          {...formItemLayout}
        >
          {getFieldDecorator('ruleCode', {
            rules: [{
              required: true,
              message: messages('common.please.input')/*请输入*/,
            }]
          })(
            <Input disabled={!!id || disabled} maxLength={50}/>
          )}
        </FormItem>
        <FormItem
          label={messages('expense-14.key377')/*规则名称*/}
          {...formItemLayout}
        >
          {getFieldDecorator('ruleName', {
            rules: [{
              required: true,
              message: messages('common.please.input')/*请输入*/,
            }]
          })(
            <Input disabled={disabled} maxLength={50}/>
          )}
        </FormItem>
      </div>
    )
  }
}

export default AutoAuditRuleSlideHead;

